//
//  TAGViewController.m
//  商城
//
//  Created by runone02 on 2018/9/13.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "TAGViewController.h"
#import "ChannelTags.h"

@interface TAGViewController ()

@property (strong, nonatomic)  UILabel *tagLabel;
/** */
@property (nonatomic,strong) UIButton *chooseBtn;
/** */
@property (nonatomic,strong) NSMutableArray *myTags;
/** */
@property (nonatomic,strong) NSMutableArray *recommandTags;
@end

@implementation TAGViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.chooseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.chooseBtn setTitle:@"选择标签" forState:UIControlStateNormal];
    [self.chooseBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.chooseBtn.backgroundColor = [UIColor lightGrayColor];
    [self.chooseBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.chooseBtn];
    [self.chooseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view).with.offset(-30);
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(30);
    }];
    
    self.tagLabel = [[UILabel alloc]init];
    self.tagLabel.textColor = [UIColor blackColor];
    self.tagLabel.numberOfLines = 0;
    [self.view addSubview:self.tagLabel];
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.chooseBtn.mas_top).with.offset(-30);
        make.left.mas_equalTo(self.view).with.offset(30);
        make.right.mas_equalTo(self.view).with.offset(-30);
    }];
    
    _myTags = @[@"关注",@"推荐",@"热点",@"北京",@"视频",@"社会",@"图片",@"娱乐",@"问答",@"科技",@"汽车",@"财经",@"军事",@"体育",@"段子",@"国际",@"趣图",@"健康",@"特卖",@"房产",@"美食"].mutableCopy;
    _recommandTags = @[@"小说",@"时尚",@"历史",@"育儿",@"直播",@"搞笑",@"数码",@"养生",@"电影",@"手机",@"旅游",@"宠物",@"情感",@"家居",@"教育",@"三农"].mutableCopy;
    
}

- (void)chooseBtn:(id)sender {
    WEAKSELF
    //秀出来选择框
    ChannelTags *controller = [[ChannelTags alloc]initWithMyTags:_myTags andRecommandTags:_recommandTags];
    [self presentViewController:controller animated:YES completion:^{}];
    
    //所有的已选的tags
    __block  NSMutableString *_str = @"已选：\n".mutableCopy;
    controller.choosedTags = ^(NSArray *chooseTags, NSArray *recommandTags) {
        weakSelf.myTags = @[].mutableCopy;
        weakSelf.recommandTags = @[].mutableCopy;
        for (Channel *mod in recommandTags) {
            [weakSelf.recommandTags addObject:mod.title];
        }
        for (Channel *mod in chooseTags) {
            [weakSelf.myTags addObject:mod.title];
            [_str appendString:mod.title];
            [_str appendString:@"、"];
        }
        weakSelf.tagLabel.text = _str;
    };
    //单选tag
    controller.selectedTag = ^(Channel *channel) {
        [_str appendString:channel.title];
        weakSelf.tagLabel.text = _str;
    };
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}


@end
